// pages/TopicsModule/addPost.js
const app = getApp()
Page({
    data: {
        barId: null,//所发版面的id
        title: null,//文章标题
        text: null,//富文本内容
        uploadImageURL: `http://${app.globalData.target}/post/uploadPic`
    },
    onLoad: function (options) {
        var that = this
        console.log(options.barid)
        that.setData({
            barId: options.barid
        })
    },

    bindTitleChange: function(e){
        this.setData({
            title: e.detail.value
        })
    },
    onInputtingDesc: function(e){
        this.setData({
            text: e.detail.html
        })
    },
    send: function(e){
        var that = this
        wx.request({
            url: `http://${app.globalData.target}/post/add`,
            data: {
                barId: that.data.barId,
                postTitle: that.data.title,
                postContent: that.data.text
            },
            header: {
                "hello-token": wx.getStorageSync("hello-token")
            },
            method: 'POST',
            success: function(res){
                console.log(res)
                if(res.data.code == 0){
                    var postid = res.data.result.postId
                    wx.redirectTo({
                        url: `../PostsModule/generalPost?postid=${postid}`,
                    })
                }
            },
            fail: function(e){
                console.log(e)
            }
        })
    }
})